package liudan.archetype.bean;


import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Field;

/**
 * Description:
 * Title
 * Copyright: Copyright (c) 2017
 * User: liudan
 * Created on 2017/2/17 18:00
 */
public class BeanUtils {
    public static Object getBean(String formClass, HttpServletRequest request) {
        Object o = null;
        try {
            try {
                Class clas = Class.forName(formClass);
                o = clas.newInstance();
                Field[] fields = clas.getDeclaredFields();
                for (Field f : fields) {
                    f.setAccessible(true);
                    f.set(o, request.getParameter(f.getName()));
                    f.setAccessible(false);
                }
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return o;
    }
}
